package at.ac.tuwien.dse.health.portal.dto;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * @author Bernhard Nickel
 * @author Gregor Schauer
 * @author Dominik Strasser
 */
public class ReservedSurgerySlotDTO implements Serializable{
	private String day;
	private String start;
	private String end;
	private String type;
	private String hospital;
	private String doctor;
	private boolean free;
	private Locale locale;

	private static Map<Locale, DateFormat> dateFormater = new HashMap<Locale, DateFormat>();

	private static Map<Locale, DateFormat> timeFormater = new HashMap<Locale, DateFormat>();

	private static DateFormat defaultDateFormat = new SimpleDateFormat("dd.MM.yyyy");

	private static DateFormat defaultTimeFormat = new SimpleDateFormat("HH:mm");

	static{
		dateFormater.put(Locale.GERMAN, new SimpleDateFormat("dd.MM.yyyy"));
		dateFormater.put(Locale.ENGLISH, new SimpleDateFormat("dd/MM/yyyy"));
		timeFormater.put(Locale.GERMAN, new SimpleDateFormat("HH:mm"));
		timeFormater.put(Locale.ENGLISH, new SimpleDateFormat("hh:mm aa"));
	}

	private static DateFormat getDateFormat(Locale locale) {
		DateFormat formater = dateFormater.get(locale);
		return formater != null ? formater : defaultDateFormat;
	}

	private static DateFormat getTimeFormat(Locale locale) {
		DateFormat formater = timeFormater.get(locale);
		return formater != null ? formater : defaultTimeFormat;
	}

	public ReservedSurgerySlotDTO(Locale locale, Date start, Date end, String type, String hospital, String doctor, boolean free) {
		this.day = getDateFormat(locale).format(start);
		this.start = getTimeFormat(locale).format(start);
		this.end = getTimeFormat(locale).format(end);
		this.type = type;
		this.hospital = hospital;
		this.doctor = doctor;
		this.free = free;
		this.locale=locale;
	}

	public String getDay() {
		return day;
	}

	public String getStart() {
		return start;
	}

	public String getEnd() {
		return end;
	}

	public String getType() {
		return type;
	}

	public String getHospital() {
		return hospital;
	}

	public String getDoctor() {
		return doctor;
	}

	public boolean isFree() {
		return free;
	}
}
